package org.pink7.fileBrowser5;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.SubMenu;
import android.view.Menu.Item;
import android.widget.TextView;
import android.graphics.Typeface;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.view.KeyEvent;
import android.util.Log;
import android.os.DeadObjectException;

import java.io.*;




public class textViewer extends Activity {
	
    private TextView titleText;
    private TextView bodyText;
    private String file_path;
    private String file_name;
    private BufferedReader br;
    private String input;
    private String str;
    
    private static final int LIST_ID = Menu.FIRST;
    private static final int PRETEXT_ID = Menu.FIRST + 1;
    private static final int NEXTTEXT_ID = Menu.FIRST + 2;
    private static final int ZOOM_ID = Menu.FIRST + 3;
    private static final int ZOOM_IN_ID = Menu.FIRST + 4;
    private static final int ZOOM_OUT_ID = Menu.FIRST + 5;
    
    @Override
    protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        
        setContentView(R.layout.text_view);
        
        titleText = (TextView) findViewById(R.id.title);
        bodyText = (TextView) findViewById(R.id.body);
        
        Bundle extras = getIntent().getExtras();
        this.file_path = extras.getString(fileBrowser5.FILE_PATH);
        this.file_name = extras.getString(fileBrowser5.FILE_NAME);
        
        try {
        	br = new BufferedReader(new FileReader(file_path));
        	input="";
        	while(true){
        		str = br.readLine();
        		if(str==null)
        			break;
        		input +=str;
        	}
        	
        } catch(IOException e) {
        	//
        }
        
        
        
        String title = file_name;
        String body = input; //test
        
        
       	
       	if (body != null) {
       		bodyText.setText(body);
       	}
       	int xa = bodyText.getLineCount();
       	//bodyText.setTextSize(3.0f);
       	if (title != null) {
       		titleText.setText(title+"aa"+xa);
       	}
       	int xb = bodyText.getLineCount();
       	AlertDialog.show(this, "//"+xa+"//"+xb,"OK" ,"NO",false);
       	xa = bodyText.getHeight();
       	// test
       	OnClickListener okButtonListener = new OnClickListener(){
			public void onClick(DialogInterface arg0, int arg1) {
				//
				
			}
		};
       	
		OnClickListener cancelButtonListener = new OnClickListener() {
			public void onClick(DialogInterface arg0, int arg1) {
				//Do nothing
			}
			
		};
       	AlertDialog.show(this,"Alert" ,"ddd"+xa,
       			"OK", okButtonListener,
				"Cancel", cancelButtonListener, false, null);
    }
    
    @Override
	public boolean onKeyUp(int keyCode, KeyEvent event) {
			switch (keyCode) {
			case KeyEvent.KEYCODE_DPAD_UP:
				// page up
				break;
			case KeyEvent.KEYCODE_DPAD_DOWN:				
				// page down				
				break;
			case KeyEvent.KEYCODE_DPAD_LEFT:
				// previous text file
				break;
			case KeyEvent.KEYCODE_DPAD_RIGHT:
				// next text file
				break;
			
			}

		return super.onKeyUp(keyCode, event);
    }
		
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        menu.add(0, LIST_ID, R.string.menu_list);
        menu.add(0, PRETEXT_ID, R.string.menu_pre);
        menu.add(0, NEXTTEXT_ID, R.string.menu_next);
                
        SubMenu sub = menu.addSubMenu(0, ZOOM_ID, R.string.menu_zoom);
        sub.add(0, ZOOM_IN_ID, R.string.menu_zoom_in);
        sub.add(0, ZOOM_OUT_ID, R.string.menu_zoom_out);
        
        return true;
    }
    
    
    @Override
    public boolean onMenuItemSelected(int featureId, Item item) {
        super.onMenuItemSelected(featureId, item);
        switch(item.getId()) {
        case LIST_ID:
            finish();
            break;
        case PRETEXT_ID:
        	// previous file
        	//fileBrowser5.
            break;
        case NEXTTEXT_ID:
        	// next file
        	
            break;
        case ZOOM_IN_ID:
        	float textSize1 = bodyText.getTextSize();
        	textSize1+=2;
        	bodyText.setTextSize(textSize1);
            break;    
        case ZOOM_OUT_ID:
        	float textSize2 = bodyText.getTextSize();
        	textSize2-=2;
        	bodyText.setTextSize(textSize2);
            break;
        }
        
        return true;
    }

}